#include "library2/libdatetime.h"
#include "gtest/gtest.h"
#include <time.h>

using namespace basic::library2;

TEST(GetUnixTimeTest, Zero) {
	apr_time_t t = time(NULL);
	EXPECT_EQ(t, CDateTime::GetCurrentUnixTime());
}

TEST(DateTimeObjectNowTest, Zero) {
	CDateTime * obj = CDateTime::GetCurrentDateTime();
	
	time_t t = time(NULL);
	struct tm *tt = localtime(&t);

	EXPECT_EQ(obj->GetYear(), tt->tm_year+1900);
	EXPECT_EQ(obj->GetMonth(), tt->tm_mon+1);
	EXPECT_EQ(obj->GetMinute(), tt->tm_min);
	EXPECT_EQ(obj->GetMonthDay(), tt->tm_mday);
	EXPECT_EQ(obj->GetSecond(), tt->tm_sec);

	delete obj;
}

TEST(DateTimeObjectSpecialDayTest, Zero) {
	CDateTime * obj = CDateTime::GetDateByStr("%Y-%m-%d %H:%M:%S", "2010-10-05 16:51:59");
	
	EXPECT_EQ(obj->GetYear(), 2010);
	EXPECT_EQ(obj->GetMonth(), 10);
	EXPECT_EQ(obj->GetMinute(), 51);
	EXPECT_EQ(obj->GetMonthDay(), 5);
	EXPECT_EQ(obj->GetSecond(), 59);

	EXPECT_STREQ("16:51", obj->FormatDateTimeStr("%R").c_str());
	EXPECT_STREQ("16:51:59", obj->FormatDateTimeStr("%T").c_str());
	EXPECT_STREQ("2010-10-05 16:51:59", obj->FormatDateTimeStr("%Y-%m-%d %H:%M:%S").c_str());
    
	
		
	delete obj;
}


